﻿using System.Threading.Tasks;

using KSOAdmin.IServices.System;
using KSOAdmin.Models.Core;
using KSOAdmin.Models.ViewModel;

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace KSOAdmin.Authorization.Controllers
{
    [ApiExplorerSettings(GroupName = "鉴权授权中心V1")]
    [Route("authorizationapi/Register")]
    [ApiController]
    public class RegisterController : ControllerBase
    {
        private readonly ISys_UserServices _UserServices;
        private readonly ISys_ProvinceServices _ProvinceServices;

        public RegisterController(ISys_ProvinceServices provinceServices, ISys_UserServices userServices)
        {
            this._ProvinceServices = provinceServices;
            this._UserServices = userServices;
        }
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="view_Sys"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("CreateRegister")]
        [AllowAnonymous]
        public async Task<ResponseModel> CreateRegisterAsync([FromBody] View_Sys_User view_Sys)
        {
            try
            {
                var Response = await _UserServices.CreateRegister(view_Sys);
                return Response;
            }
            catch (System.Exception ex)
            {
                throw new System.Exception(ex.Message);
            }
        }

        /// <summary>
        /// 获取地区
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        [Route("Provinces")]
        public async Task<ResponseModel> ProvincesAsync(string types)
        {
            try
            {
                if (types == "KSOAdminRegister")
                {
                    return ResponseModel.Success("返回成功", await _ProvinceServices.RegionList());
                }
                else
                {
                    return ResponseModel.Fail("返回成功", 401);
                }
            }
            catch (System.Exception ex)
            {
                throw new System.Exception(ex.Message);
            }

        }
    }
}
